package com.itsc.dao;

import java.util.List;

import org.hibernate.Query;

import com.itsc.entities.CenterImageDes;
import com.itsc.util.page.Page;

@SuppressWarnings("unchecked")
public class CenterImageDesDao extends BaseDao<CenterImageDes>{
	public Boolean checkDepartment(String name){
		String hql = "from CenterImageDes where cid_name=?";
		Query query = getSession().createQuery(hql);
		query.setString(0, name);
		List<CenterImageDes> list = query.list();
		if(list.size()==0){
			return true;
		}else{
			return false;
		}
	}
	
	public Integer checkIdByDepartment(String name){
		String hql = "from CenterImageDes where cid_name=?";
		Query query = getSession().createQuery(hql);
		query.setString(0, name);
		List<CenterImageDes> list = query.list();
		Integer id = list.get(0).getCid_id();
		return id;
	}

	public List<CenterImageDes> search(String searchname, Page page) {
		searchname = searchname == null?"":searchname;
		String hql = "from CenterImageDes where cid_name like ?";
		Query query = getSession().createQuery(hql);
		query.setString(0, "%" + searchname + "%");
		if (page != null) {
			query.setFirstResult(page.getBeginIndex());
			query.setMaxResults(page.getPageSize());
		}
		return query.list();
	}
}
